/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package io.renren.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * renren-fast解决了跨域，所以最开始没跨域问题，
 * 但后面加了gateway网关，让网关代理请求，网关没设置跨域，就会出现跨域问题
 * 所以需要去通过处理响应给浏览器的信息解决跨域问题（告诉浏览器，后台服务器允许你跨域）
 * renren-fast本身的跨域处理必须舍弃，否则会出现重复声明跨域配置的问题，控制台会报错
 * Access to XMLHttpRequest at 'http://localhost:88/api/sys/login'
 * from origin 'http://localhost:8001' has been blocked by CORS policy:
 * The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:8001, http://localhost:8001',
 * but only one is allowed.
 */
//@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
            .allowedOrigins("*")
            .allowCredentials(true)
            .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
            .maxAge(3600);
    }
}